//app.js
App({
  globalData: {
    myuuid:0,
    myopenid:0
  },
  getuuid:function(len, radix){//生成uuid
    var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
    var uuid = [],i;
    radix = radix || chars.length;
    if (len) {
      // Compact form
      for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
    } else {
      // rfc4122, version 4 form
      var r;
    // rfc4122 requires these characters
      uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
      uuid[14] = '4';
       // Fill in random data.  At i==19 set the high bits of clock sequence as
      // per rfc4122, sec. 4.1.5
      for (i = 0; i < 36; i++) {
        if (!uuid[i]) {
          r = 0 | Math.random() * 16;
          uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
        }
      }
    }
        return uuid.join('');
  },
  onLaunch: function () {
    var that =this;
    wx.login({
      success:(res)=>{
        const userCode=res.code;
        if(userCode){ 
          wx.request({
            url: 'http://47.115.152.5:8080/wechat/code2Session.do',
            data:{
             // encryptedData:user_eData,
             // iv:user_iv,
              code:userCode
          },
            header: {
              'content-type': 'application/json' 
          },
            method:'GET',
            success:(res)=>{
              that.globalData.myopenid=res.data.data.openid;
              wx.setStorageSync('openid', res.data.data.openid);
              wx.setStorageSync('session_key', res.data.data.session_key);
             // console.log(this.globalData.myopenid);
          },
            fail:(res)=>{
              console.log(res);
          }
        })
      }
      }
    })
      /*this.globalData.myuuid=getuuid(40,16);*/
     /*
      wx.request({
        url: 'http://47.115.152.5:8080/listen_pay.do',
        data:{
          openid:openid,
          uuid:uuid
        },
        header: {
          'content-type': 'application/json' 
      },
        method:'GET',
        success:(res)=>{
          console.log(res);
         // console.log(res.data.data.session_key);
         
      }
        
      })*/
    /*// 获取用户信息
    wx.getSetting({
      success: res => {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称，不会弹框
          wx.getUserInfo({
            success: res => {
              // 可以将 res 发送给后台解码出 unionId
              this.globalData.userInfo = res.userInfo

              // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
              // 所以此处加入 callback 以防止这种情况
              if (this.userInfoReadyCallback) {
                this.userInfoReadyCallback(res)
              }
            }
          })
        }
      }
    })*/
  }
  
})